#/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2022/1/11 10:06
# @Author  : wf
# @Email   : wf@163.com
# @File    : sjhome_page.py
# @Software: PyCharm
"""添加商机界面"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains
url = 'http://192.168.1.30/crm'
shangji_locator=(By.XPATH,'/html/body/div[1]/div/div/div[2]/ul[1]/li[3]/a')
Tianjiashangji_locator=(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div/a')
gouxuankehu_locator=(By.XPATH,'//*[@id="datas"]/tr[1]/td[1]/input[1]')
kehu_queding_locator=(By.XPATH,'/html/body/div[10]/div[3]/div/button[1]/span')
fuzerenxuanzekuang_locator=(By.ID,"owner_name")
kehuxuanzekuang_locator=(By.NAME,"customer_name")
shangjijine_locator=(By.ID,'total_price')
shangjiming_locator=(By.CSS_SELECTOR,"#name")
lianxiren_locator=(By.CSS_SELECTOR,"#contacts_name")
shengxialakuang_locator=(By.NAME,"contract_address['state']")
shixialakuang_locator=(By.NAME,"contract_address['city']")
xianxialakuang_locator=(By.NAME,"contract_address['area']")
jiedaoxinxi_locator=(By.NAME,"contract_address['street']")
shangjileixing_locator=(By.CSS_SELECTOR,"#type")
zhuangtai_locator=(By.NAME,"status_id")
shangjilaiyuan_locator=(By.NAME,"origin")
yingdanlv_locator=(By.NAME,"gain_rate")
chengjiaojia_locator=(By.ID,"estimate_price")
xiacilianxishijian_locator=(By.NAME,"nextstep_time")
lianxineirong_locator=(By.NAME,"nextstep")
beizhu_locator=(By.XPATH,'//*[@id="description"]')
tianjiachanpin_locator=(By.XPATH,'//*[@id="form1"]/table/tbody/tr[12]/th/input')
gouxuanchanpin_locator=(By.XPATH,'//*[@id="data"]/tr[1]/td[1]/input[1]')
queren_locator=(By.CSS_SELECTOR,'body > div:nth-child(22) > div.ui-dialog-buttonpane.ui-widget-content.'
                                'ui-helper-clearfix > div > button:nth-child(1) > span')
baocun_locator=(By.CSS_SELECTOR,"#form1 > table > tfoot > tr > td > input:nth-child(1)")
class SjHome():
    #点击商机按钮
    def __init__(self,driver):
        self.driver=driver
    def input_shangji(self):
        self.driver.find_element(*shangji_locator).click()
    #点击添加商机按钮
    def input_tianjiashangji(self):
        self.driver.find_element(*Tianjiashangji_locator).click()
    #点击客户输入框
    def input_kehuxuanzekuang(self):
        self.driver.find_element(*kehuxuanzekuang_locator).click()
        self.driver.find_element(*gouxuankehu_locator).click()
        self.driver.find_element(*kehu_queding_locator).click()
    #输入商机金额
    def input_shangjijine(self,shangjijine):
        self.driver.find_element(*shangjijine_locator).send_keys(shangjijine)
    #输入商机名
    def input_shangjiming(self,shangjiming):
        self.driver.find_element(*shangjiming_locator).send_keys(shangjiming)
    #输入联系人
    def input_lianxiren(self,lianxiren):
        self.driver.find_element(*lianxiren_locator).send_keys(lianxiren)
    #输入城市
    def input_shengxialakuang(self,shengxialakuang):
        self.driver.find_element(*shengxialakuang_locator).send_keys(shengxialakuang)
    #输入地区
    def input_diqu(self,diqu):
        self.driver.find_element(*shixialakuang_locator).send_keys(diqu)
    #输入商机类型
    def input_shangjileixing(self,shangjileixing):
        self.driver.find_element(*shangjileixing_locator).send_keys(shangjileixing)
    #输入商机来源
    def input_shangjilaiyuan(self,shangji_laiyuan):
        self.driver.find_element(*shangjilaiyuan_locator).send_keys(shangji_laiyuan)
    #输入赢单率
    def input_yingdanlv(self,yingdanlv):
        self.driver.find_element(*yingdanlv_locator).send_keys(yingdanlv)
    #输入预计成交金额
    def input_chengjiaojia(self,yujijiage):
        self.driver.find_element(*chengjiaojia_locator).send_keys(yujijiage)
    #输入下次联系时间
    def input_xiacilianxishijian(self,next_time):
        self.driver.find_element(*xiacilianxishijian_locator).send_keys(next_time)
        action=ActionChains(self.driver)
        action.move_by_offset(60,90).click().perform()
    #输入下次联系内容
    def input_lianxineirong(self,next_nextstep):
        self.driver.find_element(*lianxineirong_locator).send_keys(next_nextstep)
    #输入备注
    def input_beizhu(self,description):
        self.driver.find_element(*beizhu_locator).send_keys(description)
    #点击添加产品
    def input_tianjiachanpin(self):
        self.driver.find_element(*tianjiachanpin_locator).click()
    #输入要添加的产品
    def input_gouxuanchanpin(self):
        self.driver.find_element(*gouxuanchanpin_locator).click()
    #点击ok
    def input_queren(self):
        self.driver.find_element(*queren_locator).click()
    #点击保存
    def input_baocun(self):
        self.driver.find_element(*baocun_locator).click()
    def sj_duanyan(self):
        sj_locator=(By.XPATH,'//*[@id="form1"]/table/tbody/tr[6]/td[1]')
        return self.driver.find_element(*sj_locator).text
# @Time    : 2022/1/11 14:46
# @Author  : wyy
# @Email   : 1915059545@qq.com
# @File    : sjhome_page.py
# @Software: PyCharm
"""商机主页"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
#点击商机按钮
sj_locator=(By.XPATH,'/html/body/div[1]/div/div/div[2]/ul[1]/li[3]/a')
#推进商机按钮
tuijin_locator=(By.LINK_TEXT,"推进")
#末页按钮
moye_locator=(By.LINK_TEXT,'末页')
#删除按钮
sc_locator=(By.ID,"delete")
#进入商机详情页
sjxqy_locator=(By.XPATH,'//*[@id="form1"]/table/tbody/tr[1]/td[12]/a[1]')
#添加商机按钮
tianjiashangji_locator=(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div/a')
#前进到阶段下拉框
xialakuang_locator=(By.CSS_SELECTOR,"#dialog-advance > form > table > tbody > tr:nth-child(2) > td:nth-child(2) > select")
#下次联系时间
xclxsj_locator=(By.CSS_SELECTOR,"#nextstep_time")
#联系内容
neirong_locator=(By.CSS_SELECTOR,"#nextstep")
#阶段描述
miaoshu_locator=(By.XPATH,'//*[@id="dialog-advance"]/form/table/tbody/tr[4]/td[2]/textarea')
#推进里面的推进
tuijin_tuiijn_locator=(By.CSS_SELECTOR,"#dialog-advance > form > table > tbody > tr:nth-child(5) > td:nth-child(2) > input.btn.btn-primary")
class Shangji_Home:
    def __init__(self,driver):
        self.driver=driver
    #点击商机按钮进入商机主页
    def click_shangji(self):
        self.driver.find_element(*shangji_locator).click()
    #点击推进按钮，进入推进页面
    def click_tuijin(self):
        self.driver.find_element(*tuijin_locator).click()
    #完成推进信息
    def input_tuijin(self,index):
        xialakuang_element = self.driver.find_element(*xialakuang_locator)
        xialakuang_select = Select(xialakuang_element)
        xialakuang_select.select_by_index(index)
    #输入下次联系时间
    def input_xclxtome(self,xclxtime):
        self.driver.find_element(*xiacilianxishijian_locator).send_keys(xclxtime)
    #输入下次联系内容
    def input_neirong(self,neirong):
        self.driver.find_element(*neirong_locator).send_keys(neirong)
    #输入阶段描述
    def input_miaoshu(self,miaoshu):
        self.driver.find_element(*miaoshu_locator).send_keys(miaoshu)
    #点击【推进】
    def click_tj(self):
        self.driver.find_element(*tuijin_tuiijn_locator).click()


    #点击删除
    def click_shanchu(self):
        self.driver.find_element(*sc_locator).click()
    #点击查看,进入商机详情页
    def click_sjxq(self):
        self.driver.find_element(*sjxqy_locator).click()
    #点击末页
    def click_moye(self):
        self.driver.find_element(*moye_locator).click()
